$(document).ready(function() {
	ko.applyBindings(new homeViewModel(), $("#home-container")[0]);
	
	if(getParameterByName('successRegistration') === 'ok'){
		$(".msgText").hide();
		$("#userCreationMsg").show();
		$("#successOperation").modal('show')
			.on('hidden.bs.modal', function () {
				history.replaceState("object or string", "title", getCompletePath("home"));
			});
	}
	
	$('#search_container').parallax("50%", 0.1);
	//$('#search_box').parallax("50%", 0.4);
});

function homeViewModel() {
	var self = this;
	
	self.products = ko.observableArray();
	self.markets = ko.observableArray();
	
	self.showProducts = function(products) {
		$(products).show();
	};
	
	self.showMarkets = function(markets) {
		$(markets).show();
	};
	
	self.products($.map(highlightProducts, function (product) { return new Product(product); }));
	self.markets($.map(highlightMarkets, function (market) { return new Market(market); }));
	
	self.position = 2;
	self.isMoving = false;
	self.moveProductRight = function() {
		if(self.position < 4 && !self.isMoving) {
			self.isMoving = true;
			self.position += 1;
			$("#productsHomeUl").animate({
		    	"margin-left": "-=287"
		    }, 1000, function() { 
		    	self.isMoving = false;
		    });
		}
    };
	
	self.moveProductLeft = function() {
		if(self.position > 0 && !self.isMoving) {
			self.isMoving = true;
			self.position -= 1;
			$("#productsHomeUl").animate({
		    	"margin-left": "+=287"
		    }, 1000, function() { 
		    	self.isMoving = false;
		    });
		}
    };
};